{extend name="../../base/view/common/base" /}
{block name="style"}
{include file="/approve/add_style" /}
{/block}
<!-- 主体 -->
{block name="body"}
<form class="layui-form p-4">
	<h3 class="pb-3">用车审批</h3>
	{eq name="$id" value="0"}
	<table class="layui-table layui-table-form">
		<tr>
			<td class="layui-td-gray">开始时间<font>*</font></td>
			<td>
				<input id="start_time_a" name="start_time_a" autocomplete="off" class="layui-input select-time" value="" readonly lay-verify="required" placeholder="请选择时间" lay-reqText="请选择时间">
			</td>
			<td>
				<input id="start_time_b" name="start_time_b" autocomplete="off" class="layui-input select-datetime" value="" readonly lay-verify="required" placeholder="请选择时间" lay-reqText="请选择时间">
			</td>
			<td class="layui-td-gray">结束时间<font>*</font></td>
			<td>
				<input id="end_time_a" name="end_time_a" autocomplete="off" class="layui-input select-time" value="" readonly lay-verify="required" placeholder="请选择时间" lay-reqText="请选择时间">
			</td>
			<td>
				<input type="hidden" name="duration" value="">
				<input id="end_time_b" name="end_time_b" autocomplete="off" class="layui-input select-datetime" value="" readonly lay-verify="required" placeholder="请选择时间" lay-reqText="请选择时间">
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray">用车时长</td>
			<td colspan="5" id="duration">-</td>
		</tr>
		<tr>
			<td class="layui-td-gray-2">用车目的地<font>*</font></td>
			<td colspan="2"><input type="text" name="address" value="" autocomplete="off" placeholder="请输入用车目的地" lay-verify="required" lay-reqText="请输入用车目的地" class="layui-input"></td>
			<td class="layui-td-gray">车辆选择<font>*</font></td>
			<td colspan="2">
				<select name="detail_type" lay-verify="required" lay-reqText="请选择">
				  <option value="">--请选择--</option>
				  {volist name=":oa_car_cate()" id="vo"}
				  <option value="{$vo.id}">{$vo.title}[{$vo.name}]</option>
				  {/volist}
				</select>
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray">用车事由<font>*</font></td>
			<td colspan="5">
				<textarea name="content" placeholder="请输入用车事由" class="layui-textarea" lay-verify="required" lay-reqText="请输入用车事由"></textarea>
			</td>
		</tr>
	</table>
	{else/}
	<table class="layui-table layui-table-form">
		<tr>
			<td class="layui-td-gray">开始时间<font>*</font></td>
			<td>
				<input id="start_time_a" name="start_time_a" autocomplete="off" class="layui-input select-time" value="{$detail.start_time_a}" readonly lay-verify="required" placeholder="请选择时间" lay-reqText="请选择时间">
			</td>
			<td>
				<input id="start_time_b" name="start_time_b" autocomplete="off" class="layui-input select-datetime" value="{$detail.start_time_b}" readonly lay-verify="required" placeholder="请选择时间" lay-reqText="请选择时间">
			</td>
			<td class="layui-td-gray">结束时间<font>*</font></td>
			<td>
				<input id="end_time_a" name="end_time_a" autocomplete="off" class="layui-input select-time" value="{$detail.end_time_a}" readonly lay-verify="required" placeholder="请选择时间" lay-reqText="请选择时间">
			</td>
			<td>
				<input type="hidden" name="duration" value="{$detail.duration}">
				<input id="end_time_b" name="end_time_b" autocomplete="off" class="layui-input select-datetime" value="{$detail.end_time_b}" readonly lay-verify="required" placeholder="请选择时间" lay-reqText="请选择时间">
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray">用车时长</td>
			<td colspan="5" id="duration">共{$detail.duration}小时</td>
		</tr>
		<tr>
			<td class="layui-td-gray-2">用车目的地<font>*</font></td>
			<td colspan="2"><input type="text" name="address" value="{$detail.address}" autocomplete="off" placeholder="请输入用车目的地" lay-verify="required" lay-reqText="请输入用车目的地" class="layui-input"></td>
			<td class="layui-td-gray">车辆选择<font>*</font></td>
			<td colspan="2">
				<select name="detail_type" lay-verify="required" lay-reqText="请选择">
				  <option value="">--请选择--</option>
				  {volist name=":oa_car_cate()" id="vo"}
				  <option value="{$vo.id}" {eq name="$detail.detail_type" value="$vo.id"}selected=""{/eq}>{$vo.title}[{$vo.name}]</option>
				  {/volist}
				</select>
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray">用车事由<font>*</font></td>
			<td colspan="5">
				<textarea name="content" placeholder="请输入用车理由" class="layui-textarea" lay-verify="required" lay-reqText="请输入用车理由">{$detail.content}</textarea>
			</td>
		</tr>
	</table>
	{/eq}
	{include file="/approve/add_flow" /}
</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
/**
 * 工时计算
  */
function leaveTime() {
	var data_1 = $('#start_time_a').val();
	var data_1_1 = $('#start_time_b').val();
	var data_2 = $('#end_time_a').val();
	var data_2_1 = $('#end_time_b').val();
	if(data_1=='' || data_1_1=='' || data_2=='' || data_2_1==''){
		return 0;
	}	

    var start_date = data_1+' '+data_1_1; 
    var end_date = data_2+' '+data_2_1; 
	var start = new Date(start_date.replace(/-/g,'/'));
	var end = new Date(end_date.replace(/-/g,'/'));
	var diff=end.getTime() - start.getTime();//时间差的毫秒数 
    if(diff<0){
		return 0;
	}   
    //计算出小时数 
    var hours=diff/(3600*1000);
	console.log(hours);
    return hours.toFixed(1); 
}

const moduleInit = ['tool','employeepicker'];
	function gouguInit() {
		var form = layui.form,tool=layui.tool, employeepicker = layui.employeepicker,laydate = layui.laydate;	
		if (typeof (flowStep) == "function") {
			flowStep();
		}		  		
		//日期时间范围
		lay('.select-time').each(function () {
			laydate.render({
				elem: this,
				trigger: 'click',
				done:function(){
					var hours = leaveTime();
					if(hours == 0){
						$('#duration').html('-');
					}
					else{
						$('#duration').html('共'+hours+'小时');
					}
					$('[name="duration"]').val(hours);
				}
			});
		});
		
		//选择具体时间
		lay('.select-datetime').each(function () {
			laydate.render({
				elem: this,
				trigger: 'click',
				type: 'time',
				format: 'HH:mm',
				btns: ['clear', 'confirm'],
				ready: function (date) {
				   var dom = $(".laydate-time-list").children("li");
				   for (var i = 0; i < dom.length; i++) {
					   if (i == 2 || i == 5) {
						   $(dom[i]).remove();
					   } else if(i==1||i==4) {
						   var li = $(dom[i]).children("ol").children("li")
						   for (var j = 0; j < li.length; j++) {
							   if ($(li[j]).text() != 00 && $(li[j]).text()!=30) {
								   $(li[j]).remove();
							   }
						   }
					   }
					}
				},
				done:function(){
					var hours = leaveTime();
					if(hours == 0){
						$('#duration').html('-');
					}
					else{
						$('#duration').html('共'+hours+'小时');
					}
					$('[name="duration"]').val(hours);
				}
			});
		});	
	}
</script>
{/block}
<!-- /脚本 -->